{%- if grains['role'] == 'so-eval' -%}
{%- set ES = salt['pillar.get']('manager:mainip', '') -%}
{%- else %}
{%- set ES = salt['pillar.get']('elasticsearch:mainip', '') -%}
{%- endif %}
{%- set FEATURES = salt['pillar.get']('elastic:features', False) %}
{%- set ES_USER = salt['pillar.get']('elasticsearch:auth:users:so_elastic_user:user', '') %}
{%- set ES_PASS = salt['pillar.get']('elasticsearch:auth:users:so_elastic_user:pass', '') %}

filter {
  if [type] =~ "live_query" {

    mutate {
        rename => {
            "[host][hostname]" => "computer_name"
        }
    }

 prune {
        blacklist_names => ["host"]
      }
    
 split {
   field => "rows"
  }
 }
}


output {
  if [type] =~ "live_query" {
    elasticsearch {
      pipeline => "osquery.live_query" 
      hosts => "{{ ES }}"
{% if salt['pillar.get']('elasticsearch:auth:enabled') is sameas true %}
      user => "{{ ES_USER }}"
      password => "{{ ES_PASS }}"
{% endif %}
      index => "so-osquery"
      template_name => "so-osquery"
      template => "/templates/so-osquery-template.json"
      template_overwrite => true
      ssl => true
      ssl_certificate_verification => false
    }
  }
}
